package com.ruoyi.activiti.listener;

import com.ruoyi.caigou.api.RemoteBuyBackReqService;
import com.ruoyi.common.core.utils.SpringUtils;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.system.api.domain.caigou.BuyBackReq;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;

/**
 * @author wangenhao
 * @className BuyBackReqListener
 * @description 采购退货申请审核监听
 * @date 2024-10-30 下午8:37
 **/
@Slf4j
public class BuyBackReqListener implements ExecutionListener {

//    private Expression approvalResult;

    public void notify(DelegateExecution delegateExecution) {
        BuyBackReq buyBackReq = new BuyBackReq();
        buyBackReq.setCode(delegateExecution.getProcessInstanceBusinessKey());
        Integer approvalResult = (Integer) delegateExecution.getVariable("approvalResult");
        String approvalOption = (String) delegateExecution.getVariable("approvalOption");
        //审核结果
        buyBackReq.setApprovalResult(approvalResult);
        buyBackReq.setApprovalOption(approvalOption);

        log.info("BuyBackReqListener notify buyBackReq:{}  approvalResult:{} approvalOption:{}", buyBackReq, approvalResult, approvalOption);
        //调用采购退货申请修改接口
        AjaxResult ajaxResult = SpringUtils.getBean(RemoteBuyBackReqService.class).updateStatusByCode(buyBackReq);
        log.info("ajaxResult:{}", ajaxResult);
    }
}
